package com.project.thisDatabase.mongo;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

@ConditionalOnProperty(name = "spring.data.mongodb.enable", havingValue = "true")
@Configuration
public class MongoDBConfig {

    @Value("${spring.data.mongodb.uri}")
    String uri;

    @Value("${spring.data.mongodb.database}")
    String database;


    @Bean
    public MongoClient mongoClient() {
        return MongoClients.create(uri);
    }
    @Bean
    public MongoTemplate mongoTemplate() {
        return new MongoTemplate(mongoClient(), database);
    }

}
